package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseType;
import com.ruoyi.base.service.IBaseTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 设备类型Controller
 *
 * @author yepanpan
 * @date 2025-03-03
 */
@RestController
@RequestMapping("/base/type")
public class BaseTypeController extends BaseController
{
    @Autowired
    private IBaseTypeService baseTypeService;

    /**
     * 查询设备类型列表
     */
    @PreAuthorize("@ss.hasPermi('base:type:list')")
    @GetMapping("/list")
    public AjaxResult list(BaseType baseType)
    {
        List<BaseType> list = baseTypeService.selectBaseTypeList(baseType);
        return success(list);
    }

    /**
     * 导出设备类型列表
     */
    @PreAuthorize("@ss.hasPermi('base:type:export')")
    @Log(title = "设备类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseType baseType)
    {
        List<BaseType> list = baseTypeService.selectBaseTypeList(baseType);
        ExcelUtil<BaseType> util = new ExcelUtil<BaseType>(BaseType.class);
        util.exportExcel(response, list, "设备类型数据");
    }


    /**
     * 获取设备类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseTypeService.selectBaseTypeById(id));
    }

    /**
     * 新增设备类型
     */
    @PreAuthorize("@ss.hasPermi('base:type:add')")
    @Log(title = "设备类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BaseType baseType)
    {
        return toAjax(baseTypeService.insertBaseType(baseType));
    }

    /**
     * 修改设备类型
     */
    @PreAuthorize("@ss.hasPermi('base:type:edit')")
    @Log(title = "设备类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BaseType baseType)
    {
        return toAjax(baseTypeService.updateBaseType(baseType));
    }

    /**
     * 删除设备类型
     */
    @PreAuthorize("@ss.hasPermi('base:type:remove')")
    @Log(title = "设备类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseTypeService.deleteBaseTypeByIds(ids));
    }
}
